﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Xceed.Wpf.Toolkit;
using OOAD_PROJEKAT;
using DAL;

namespace WpfApplication25
{
    /// <summary>
    /// Interaction logic for ponuda.xaml
    /// </summary>
    public partial class ponuda : Window
    {
        IntegerUpDown gov, gov1;
        List<PolicaOsiguranja> police = new List<PolicaOsiguranja>();
        public ponuda()
        {
            InitializeComponent();
            gov = new IntegerUpDown();
            gov.Height = 20;
            gov.Width = 120;
            gov.Minimum = 0;
            gov.Value = 0;
            gov.BorderBrush = SystemColors.ControlDarkBrush;
            mreza.Children.Add(gov);
            Grid.SetColumn(gov, 0);
            Grid.SetRow(gov, 1);
            gov1 = new IntegerUpDown();
            gov1.Height = 20;
            gov1.Width = 120;
            gov1.Minimum = 0;
            gov1.Value = 0;
            gov1.BorderBrush = SystemColors.ControlDarkBrush;
            mreza.Children.Add(gov1);
            Grid.SetColumn(gov1, 0);
            Grid.SetRow(gov1, 3);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (gov.Value > gov1.Value)
            {
                gov.BorderBrush = Brushes.Red;
                gov.ToolTip = "Neispravan opseg!";
                gov1.BorderBrush = Brushes.Red;
                gov1.ToolTip = "Neispravan opseg!";
            }
            else
            {
                gov.BorderBrush = SystemColors.ControlDarkBrush;
                gov.ToolTip = null;
                gov1.ToolTip = null;
                gov1.BorderBrush = SystemColors.ControlDarkBrush;
                DAL.DAL.PolicaDAO pol = new DAL.DAL.PolicaDAO();
                police = pol.getAll();
                foreach (PolicaOsiguranja pa in police)
                {
                    if (pa.Cijena >= gov.Value && pa.Cijena <= gov1.Value)
                        les.Items.Add(pa.Id + " " + pa.KarakteristikePolice);
                }
            }
        }

        private void les_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            String sarma = (sender as ListBoxItem).Content.ToString();
            int indeks = 0;
            for (int i = 0; i < sarma.Count(); i++)
            {
                if (sarma[i] == ' ')
                {
                    indeks = i;
                    break;
                }
            }
            String pom = sarma.Substring(0, indeks);
            foreach (PolicaOsiguranja polo in police)
            {
                if (polo.Id.ToString() == pom)
                {
                    karak.Text = polo.KarakteristikePolice;
                    ja.Text = polo.DatumPotpisivanja.ToString();
                    ti.Text = polo.DatumIsteka.ToString();
                    ona.Text = polo.Cijena.ToString();
                }
            }
        }
    }
}
